package no.ntnu.fp.gui.listeners;

import java.io.IOException;

import no.ntnu.fp.client.exceptions.NetworkException;
import no.ntnu.fp.gui.events.NoticeReadEvent;
import no.ntnu.fp.model.Notice;
import no.ntnu.fp.services.NoticeService;

public class NoticeReadListener implements GuiListener<NoticeReadEvent> {

	private final NoticeService noticeService;
	
	public NoticeReadListener(NoticeService noticeService) {
		this.noticeService = noticeService;
	}

	@Override
	public void handleEvent(NoticeReadEvent evt) {
		Notice notice = evt.getNotice();
		try {
			noticeService.markAsRead(notice);
		} catch (IOException ex) {
			throw new NetworkException("Could not mark notice as read", ex);
		}
	}

	@Override
	public boolean isLongRunningListener() {
		return false;
	}
}
